﻿<%@ WebHandler Language="C#" Class="hLoginLog" %>

using System;
using System.Web;
using System.Data;
using System.Collections.Generic;
using System.Web.SessionState;
using Entities.System;
using BLL.System;
using CommonLib; 

public class hLoginLog : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest (HttpContext context) {
        handle(context);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
    
    private void handle(HttpContext context)
    {
        string action = context.Request.QueryString["action"];
        string result = string.Empty;
        int? pageSize = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageSize = Convert.ToInt32(context.Request["rows"]);
        int? pageNum = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageNum = Convert.ToInt32(context.Request["page"]);
        Dictionary<string, string> dicLike = new Dictionary<string, string>();
        Dictionary<string, string> dicEqual = new Dictionary<string, string>();
        Dictionary<string, string> dicIn = new Dictionary<string, string>();
        try
        {
            if (context.Session["user"] == null) throw new Exception("登录超时！");
            User user = context.Session["user"] as Entities.System.User;

            switch (action )
            {
                case "get":
                    if (context.Request["sMenu"] != null) dicIn.Add("l.FUNCTION_KEY", context.Request["sMenu"]);
                    string dateCondi = string.Empty; 
                    if (context.Request["startDate"] != null)
                    {
                        dateCondi += string.Format("and l.LOGIN_DATE >= CONVERT(datetime, '{0}')", context.Request["startDate"]); 
                    }
                    if (context.Request["endDate"] != null)
                    {
                        dateCondi += string.Format("and l.LOGIN_DATE <= CONVERT(datetime, '{0}')", context.Request["endDate"]);
                    }
                    result = LoginLogBO.get(dicLike, dicEqual,dicIn ,dateCondi ,  pageSize, pageNum);
                    break;

                case "getdetail":
                    string dateCondi2 = string.Empty;
                    if (context.Request["startDate"] != null)
                    {
                        dateCondi2 += string.Format("and l.LOGIN_DATE >= CONVERT(datetime, '{0}')", context.Request["startDate"]);
                    }
                    if (context.Request["endDate"] != null)
                    {
                        dateCondi2 += string.Format("and l.LOGIN_DATE <= CONVERT(datetime, '{0}')", context.Request["endDate"]);
                    }
                    if (context.Request["funkey"] != null) dicLike.Add("l.FUNCTION_KEY", context.Request["funkey"]);
                    result = LoginLogBO.getDetails(dicLike, dicEqual,dateCondi2,pageSize, pageNum);
                    break;                    
                        
                case "del":
                    //删除
                    result = LoginLogBO.delLoginLog(context);
                    break;
            }
        }
        catch (Exception ex)
        {
            var error = new Entities.Status { Success = false, Message = ex.Message };
            result = error.ToJson();

        }
        finally
        {
            context.Response.Write(result);
        }
    }
}
